package com.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description: 日期工具类
 */
public class DateUtil {
    
    /**
     * @Description: 传入一个日期能查看年份、月份、季度、日期、星期数、是365天中的哪一天
     * @Param:
     * @return:
     */
    public static String getDateInfo(Date date) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
//        System.out.println("输入日期为：" + date); // 输入日期

        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd");
        String date1 = "日期为："+sdf1.format(date);

        int weekDay = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 获取今天星期几（以星期日为第一天）
//        System.out.print("星期" + weekDay + " ");
        String weekDay1 = " 星期" + weekDay + " ";


        int week = calendar.get(Calendar.WEEK_OF_YEAR); // 获取今年第几周
//        System.out.print("今年第" + week + "个星期 ");
        String week1 = "是自身年份第" + week + "个星期 ";

        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); // 获取今天是本月第几天
//        System.out.println(" 是这个月的第 " + dayOfMonth + " 天 ");
        String dayOfMonth1 = " 是自身月份的第" + dayOfMonth + "天 ";

        int dayOfWeekInMonth = calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH); // 获取今天是本月第几周
//        System.out.println("是本月第 " + dayOfWeekInMonth + " 周 ");
        String dayOfWeekInMonth1 = "是自身月份第" + dayOfWeekInMonth + "周 ";

        int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); // 获取今天是今年第几天
//        System.out.println("是今年第 " + dayOfYear + " 天 ");
        String dayOfYear1 = "本自年份第" + dayOfYear + "天 ";

        int month = calendar.get(Calendar.MONTH)+1; // 获取今年第几月
        String monthOfYear = " ";
        if(month>=1 && month<=3){
            //System.out.print(" 今年第一季度 ");
            monthOfYear = " 位于自身年份第一季度 ";
        }else if(month>=4 && month<=6){
            monthOfYear = " 位于自身年份第二季度 ";
        }else if(month>=7 && month<=9){
            monthOfYear = " 位于自身年份第三季度 ";
        }else if(month>=10 && month<=12){
            monthOfYear = " 位于自身年份第四季度 ";
        }else{
            monthOfYear = " ";
        }

        String result = date1 + weekDay1 + week1 + dayOfMonth1 + dayOfWeekInMonth1 + dayOfYear1 + monthOfYear;

        return result;
    }


}
